package leetcode1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 09 - 08
 * Time:9:12
 */
public class Test01 {
    /***
     * 1.给定一个整数在数组nums 和一个目标值target，请在该数组中找出和为目标值的那两个整数，并返回它们的数组下标；
     * nums = [2,7,11,15] target = 9;
     * nums[0] + nums[1] = ,2 + 7 = 9;
     * 返回：[0,1]
     * @param nums
     * @param targer
     * @return
     */
    public static int[] twoNumSum(int[] nums,int targer){
        if(nums == null){
            return null;
        }
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if(nums[i] + nums[j] == targer){
/*                    int[] ret = new int[]{i,j};
                    return ret;*/
                    return new int[]{i,j};//匿名数组
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3};
        int[] ret = twoNumSum(arr,4);
        System.out.println(Arrays.toString(ret));

    }
}
